#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>



int main()
{
  printf("testexec ... begin!\n");
  pid_t id=fork();
  if(id==0)
  {
   putenv("HHHH=111111111111");
  //父进程本身又一批环境变量
   char *const argv[]=
   {
    (char*) "mypragma",
    (char*) "-a",
    (char*) "-b",
     NULL
   };

   char *const envp[]=
   {
    (char*) "HAHA=111111",
    (char*) "HEHE=222222",
      NULL
   };
   extern char**environ;


    printf("child pid:%d\n",getpid());
    sleep(2);
    execvpe("./mypragma",argv,environ);
   // execvpe("./mypragma",argv,envp);
    //execl("/usr/bin/python3","python3","test.py",NULL);
    //execl("/usr/bin/bash","bash","test.sh",NULL);
   // execl("./mypragma","mypragma",NULL);
    
    //child
     //sleep(2);
     //char *const argv[]=
     //{
     // (char*) "ls",
     // (char*) "-l",
     // (char*) "-a",
     // (char*) "--color",
     //  NULL
     //};
     ////execl("/usr/bin/top","top",NULL);
    //// execv("/usr/bin/ls",argv);
    
     //execlp("top","top",NULL);
     //execvp("ls",argv);
     
     exit(1);
    
  
  }

  //father
  int status=0;
  pid_t rid=waitpid(id,&status,0);
  if(rid>0)
  {
    printf("father wait success,child exit code:%d\n",WIFEXITED(status));

  }


  printf("testexec ... end1\n");

  return 0;
}
